package com.mall.controller;


import com.mall.dto.AfterSalesPageQueryDTO;
import com.mall.po.AfterSales;
import com.mall.result.PageResult;
import com.mall.result.Result;
import com.mall.service.AfterSalesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.AfterAdvice;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售后信息 前端控制器
 * </p>
 *
 * @author itlxc
 * @since 2024-04-28
 */
@RestController
@RequestMapping("/admin/afterSales")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "售后管理相关接口")
public class AfterSalesController {

    private final AfterSalesService afterSalesService;

    /**
     * 售后分页查询
     * @param afterSalesPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("售后分页查询")
    public Result<PageResult> afterSalesPageQuery(AfterSalesPageQueryDTO afterSalesPageQueryDTO) {
        log.info("售后分页查询：{}", afterSalesPageQueryDTO);
        PageResult pageResult = afterSalesService.afterSalesPageQuery(afterSalesPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 处理售后
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/handle/{status}")
    @ApiOperation("处理售后")
    public Result handleAfterSales(@PathVariable Integer status, Long id) {
        log.info("处理售后：id：{}，status：{}", id, status == 2 ? "同意" : "拒绝");
        afterSalesService.handleAfterSales(status, id);
        return Result.success();
    }
}
